@extends('Admin.base')

@section('content')
    <style type="text/css" media="screen">
        .lay-dd {
            line-height: 40px;
            /*height: 40px;*/
        }

        .layui-con {
            padding-left: 30px;
        }

        .lay-price {
            width: 150px;
            display: inline-block;
        }
    </style>
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>会员详情</legend>
            </fieldset>
        </div>
        <div class="layui-card-body">

            <div class="layui-con">
                <div class="layui-row">
                    <div class="layui-col-md12">
                        <div class="layui-row">
                            <div class="layui-col-md2">
                                <div class="lay-dd">
                                    <img src="{{$data->avatar}}" width="80">
                                </div>
                            </div>
                            <div class="layui-col-md5">
                                <div class="lay-dd">微信昵称: {{$data->nickname}}</div>
                                <div class="lay-dd">真实姓名: {{$data->realname}}</div>
                                <div class="lay-dd">会员ID: {{$data->number}}</div>
                                <div class="lay-dd">注册时间: {{$data->created_at}}</div>
                                <div class="lay-dd">出生日期: {{$data->birthday}}</div>
                            </div>
                            <div class="layui-col-md5">
                                <div class="lay-dd">性别: {{$data->sex_name}}</div>
                                <div class="lay-dd">手机号码: {{$data->phone}}</div>
                                <div class="lay-dd">Open ID: {{$data->openid}}</div>
                                <div class="lay-dd">最近登入小程序: {{$data->last_login}}</div>
                                <div class="lay-dd">@if($data->user_type == 1)微信号码: {{$data->wechat}} @endif </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row" style="margin-top: 20px;">
                    当前会员等级：{{$data->calcLevel}} &nbsp;&nbsp;&nbsp;{{$data->surplus_time}}
                </div>
                <div class="layui-row" style="margin-top: 20px;">
                    所属城市：{{$data->provinceInfo->name}} {{$data->cityInfo->name}} &nbsp;&nbsp;&nbsp;
                    上次收货地址：@if(count($data->userHasOrder)) {{$data->userHasOrder[0]->get_region ?? $data->userHasOrder[0]->user_address}} @endif
                </div>


                <div class="layui-row" style="margin-top: 20px;">
                    所属员工：
                    @if(!empty($inviteData))
                        {{$inviteData->realname}} &nbsp;&nbsp;
                        &nbsp; {{$inviteData->userDepartment ? $inviteData->userDepartment->number : ''}} &nbsp;&nbsp;
                        &nbsp; {{$inviteData->userDepartment ? $inviteData->userDepartment->department_name : ''}}&nbsp;
                        &nbsp;&nbsp;
                        @if ($inviteData->status == 1)
                            在职
                        @else
                            离职
                        @endif
                        &nbsp;&nbsp;&nbsp;
                    @endif
                    <button class="layui-btn layui-btn-xs" id="change">变更</button>
                </div>


                <div class="layui-row" style="margin-top: 60px;">
                    <span class="lay-price">充值余额：{{$data->money_recharge}}</span>
                    <button class="layui-btn layui-btn-xs" id="money_recharge">查看充值记录</button>
                </div>
                <div class="layui-row" style="margin-top: 20px;">
                    <span class="lay-price">八贝币余额：{{$data->money_eight_consh}}</span>
                    <button class="layui-btn layui-btn-xs" id="money_eight_consh">查看八贝币记录</button>
                </div>
                <div class="layui-row" style="margin-top: 20px;">
                    <span class="lay-price">贝壳余额：{{$data->money_consh}}</span>
                    <button class="layui-btn layui-btn-xs" id="money_consh">查看贝壳记录</button>
                </div>
                <div class="layui-row" style="margin-top: 20px;">
                    <span class="lay-price">订单数：{{$data->order_num}}</span>
                    <button class="layui-btn layui-btn-xs" id="order_list">查看相关订单</button>
                </div>
                <div class="layui-row" style="margin-top: 20px;">
                    已完成交易金额：{{$data->total_real_pay}}
                </div>
                <div class="layui-row" style="margin-top: 20px;">
                    邀请好友数：{{$data->user_has_invite_count}}
                </div>
            </div>


        </div>

    </div>
<!--             <div class="layui-form-item layui-col-md6">
    <div class="">
        <a class="layui-btn" onclick="window.history.go(-1)" >返回</a>
    </div>
</div> -->
@endsection

@section('script')
    <script src="/js/ajax.js"></script>

    <script type="text/html" id="userinfo">
        <div>
            @{{d.user_name ? d.user_name : "" }}<br>
            @{{d.user_phone ? d.user_phone : ""}}<br>
            @{{d.user_address ? d.user_address : ""}}
        </div>
    </script>

    <script>
        layui.use(['form', 'element', 'table', 'tableSelect'], function () {
            var $ = layui.$
                , form = layui.form
                , element = layui.element
                , tableSelect = layui.tableSelect
                , table = layui.table;

            //修改变更邀请人
            var searchstr = '<input style="display:inline-block;width:150px;height:30px;vertical-align:middle;margin-right:-1px;border: 1px solid #C9C9C9;" type="text" name="name" placeholder="输入姓名，ID" autocomplete="off" class="layui-input">&nbsp;&nbsp;&nbsp;部门:<select name="department" style="display:inline-block;width:150px;height:30px;vertical-align:middle;margin-right:-1px;border: 1px solid #C9C9C9;"><option value="">所有部门</option>@foreach (\App\Models\UserDepartment::get() as $value )<option value="{{$value->id}}">{{$value->department_name}}</option>@endforeach</select>&nbsp;&nbsp;&nbsp;职位:<select name="position" style="display:inline-block;width:150px;height:30px;vertical-align:middle;margin-right:-1px;border: 1px solid #C9C9C9;"><option value="">所有职位</option>@foreach (\App\Models\UserPosition::get() as $value )<option value="{{$value->id}}">{{$value->position_name}}</option>@endforeach</select>&nbsp;&nbsp;&nbsp;状态:<select name="status" style="display:inline-block;width:150px;height:30px;vertical-align:middle;margin-right:-1px;border: 1px solid #C9C9C9;"><option value="">所有状态</option>@foreach (\App\Models\User::USER_STATUS as $id => $name )<option value="{{$id}}">{{$name}}</option>@endforeach</select>&nbsp;&nbsp;&nbsp;<button class="layui-btn layui-btn-sm layui-btn-primary tableSelect_btn_search" lay-submit lay-filter="tableSelect_btn_search"><i class="layui-icon layui-icon-search"></i></button>';
            tableSelect.render({
                elem: '#change',  //定义输入框input对象
                width: 1000,
                searchstr: searchstr,
                table: {    //定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                    url: "{{route('user.invitelist',['id'=>$data->id])}}",
                    method: "post",
                    cols: [[
                        {type: 'radio'}
                        , {field: 'realname', title: '姓名',}
                        , {field: 'number', title: '会员ID',}
                        , {
                            field: 'department_name', title: '部门', templet: function (d) {
                                return d.user_department.department_name
                            }
                        }
                        , {
                            field: 'position_name', title: '职位', templet: function (d) {
                                return d.user_position.position_name
                            }
                        }
                        , {
                            field: 'status', title: '状态', templet: function (d) {
                                return d.status == 1 ? '在职' : '离职'
                            }
                        }
                    ]]
                },
                done: function (elem, data) {
                    var id = data.data[0].id;
                    $.ajax({
                        url: "{{route('user.changeinvite',['id'=>$data->id])}}"
                        , type: 'POST'
                        , dataType: 'json'
                        , data: {invite_id: id}
                        , success: function (ret) {
                            if (ret.hasOwnProperty('code') && ret.code == 200) {
                                layer.msg(ret.message, {icon: 1, time: 1000}, function () {
                                    location.reload();
                                });
                                return false;
                            }
                            layer.msg(ret.message, {icon: 2});
                        }
                        , complete: function () {
                            layer.closeAll('loading');
                        }
                    });
                }
            });

            //查看充值记录
            tableSelect.render({
                elem: '#money_recharge',  //定义输入框input对象
                width: 1000,
                searchs: 2, //1 开启搜索 2关闭
                table: {    //定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                    url: "{{route('user.moneyrecharge',['id'=>$data->id])}}",
                    method: "post",
                    cols: [[
                        {field: 'id', title: '序号',}
                        , {field: 'created_at', title: '充值时间',}
                        , {field: 'money', title: '充值金额',}
                        , {field: 'balance', title: '充值后余额',}
                    ]]
                }
            });

            //查看八贝币记录
            tableSelect.render({
                elem: '#money_eight_consh',  //定义输入框input对象
                width: 1000,
                searchs: 2, //1 开启搜索 2关闭
                table: {    //定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                    url: "{{route('user.moneyeightconsh',['id'=>$data->id])}}",
                    method: "post",
                    cols: [[
                        {field: 'created_at', title: '时间' }
                        , {field: 'number', title: '金额' }
                        , {field: 'type', title: '标题' }
                    ]]
                }
            });

            //查看贝壳记录
            tableSelect.render({
                elem: '#money_consh',  //定义输入框input对象
                width: 1000,
                searchs: 2, //1 开启搜索 2关闭
                table: {    //定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                    url: "{{route('user.moneyconsh',['id'=>$data->id])}}",
                    method: "post",
                    cols: [[
                        {field: 'created_at', title: '时间' }
                        , {field: 'number', title: '金额' }
                        , {field: 'type', title: '标题' }
                    ]]
                }
            });


            //查看订单记录
            tableSelect.render({
                elem: '#order_list',  //定义输入框input对象
                width: 1000,
                searchs: 2, //1 开启搜索 2关闭
                table: {    //定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                    url: "{{route('user.orderlist',['id'=>$data->id])}}",
                    method: "post",
                    cols: [[
                        {field: 'shop_string', title: '商品',}
                        , {field: 'online_order', title: '订单号', }
                        , {field: 'user_name', title: '买家信息', templet: "#userinfo", width: 120}
                        , {field: 'real_pay', title: '支付信息', width: 90}
                        , {field: 'express_string', title: '配送信息', width: 100}
                        , {field: 'status_name', title: '状态', width: 80}
                        , {field: 'created_at', title: '下单时间', width: 120}

                    ]]
                }
            });


        });

    </script>
@endsection